/****************************************************************************/
/*	include files
*****************************************************************************/

#include "include.h"

/****************************************************************************/
/*	Local variable  definitions*/
/**********windmill start control***********/

volatile Windmill_Components WindmillCtrl = {0};

void WindmillParaInitFun(void)
{
	WindmillCtrl.windmill_cnt = 0;
}


/**************************
*when windmill, read the hall angle;
*************************/
void WindmillGetHallAngleFun(void)
{
	if(WindmillCtrl.windmill_cnt < WINDMILL_CNT_VAL)
	{
		WindmillCtrl.windmill_cnt++;
		if(Hall.DirFlag == CW)
		{
			Hall.Angle = Hall.Angle + Hall.HallOmegaPeroid;
		}
		else if(Hall.DirFlag == CCW)
		{
			Hall.Angle = Hall.Angle - Hall.HallOmegaPeroid;
		}
		if(Hall.WindmillHallIntCnt >= 6)
		{	
//Hall.WindmillHallIntCnt,when windmill state,should happen 6s hall interrupt signal*******
			Hall.WindmillHallIntCnt = 0;
			WindmillCtrl.windmill_cnt = 0;
			Foc_lib.ClosedTargetVq = 80*Hall.HallOmegaPeroid;// 3000erpm,9V,about coffeicent 100;
			Foc_lib.Vq = Foc_lib.ClosedTargetVq;
			Foc_lib.Vd = 0;
			MOTOR_STATE = MC_FOC;
			BrigeOutputOnFun();
			Foc_lib.Angle = Hall.Angle;
			SinCosCalFun(Foc_lib.Angle);
			ResPark();
			SvpwmCalFun();
		}
	}
	else
	{
		Hall.WindmillHallIntCnt = 0;
		MOTOR_STATE = MC_CHARGE;
	}
}
	
	
void WindmillMotorIntScanFun(void)
{
	if((Hall.NowValue != Hall.Value)&&((Hall.Value == Hall.NextValue)||(Hall.Value == Hall.LastValue)))
	{
		if(MOTOR_STATE == MC_WINDMILL)
		{
/**********windmill state, read hall value and convert to angle**********/
			Hall.WindmillHallIntCnt++;
			Hall.Angle = Hall.HallAngle;
		}
	}
}


 

	
















/**********************end*********************/

 












